package com.prestamomo.vil.ppa.pmvilpage.pmfitter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.prestamomo.vil.ppa.R;
import com.prestamomo.vil.ppa.pmvilapi.PmvilSerllerPack;

import java.util.List;

public class PmvilSellerFitter extends RecyclerView.Adapter<PmvilSellerFitter.PmvilSellerHolde> {
    private Context pmvilCont;
    private List<PmvilSerllerPack> pmvilSellerList;
    private int pmvilShowNum;

    public PmvilSellerFitter(Context pmvilCont, List<PmvilSerllerPack> pmvilSellerList,int pmvilShowNum) {
        this.pmvilCont = pmvilCont;
        this.pmvilSellerList = pmvilSellerList;
        this.pmvilShowNum = pmvilShowNum;
    }

    @NonNull
    @Override
    public PmvilSellerFitter.PmvilSellerHolde onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PmvilSellerHolde(LayoutInflater.from(pmvilCont).inflate(R.layout.seller_pmvil_item_ly, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull PmvilSellerFitter.PmvilSellerHolde holder, int position) {
        if(position>pmvilShowNum-1){
            holder.sellerPmvilRl.setVisibility(View.GONE);
        }else{
            holder.sellerPmvilRl.setVisibility(View.VISIBLE);
            holder.sellerPmvilTvname.setText(pmvilSellerList.get(position).getPmvilSerllerName());
            holder.sellerPmvilTvmoney.setText(pmvilSellerList.get(position).getPmvilSerllerMoney());
            holder.pmlset_se.setText(pmvilSellerList.get(position).getReviewAmount());
            holder.seller_pmvil_tv_hkrq.setText(pmvilSellerList.get(position).getPmvilHkrq());
            holder.seller_pmvil_tv_lv.setText(pmvilSellerList.get(position).getPmvilLlv());
            holder.seller_pmvil_tv_kbf.setText(pmvilSellerList.get(position).getPmvilKbf());
            Glide.with(pmvilCont).load(pmvilSellerList.get(position).getPmvilSerllerIcon()).into(holder.sellerPmvilIv);
        }
    }

    public void setPmvilListSellers(int pmvilShowNum){
        this.pmvilShowNum = pmvilShowNum;
        notifyDataSetChanged();

    }
    @Override
    public int getItemCount() {
        return pmvilSellerList.size();
    }

    public class PmvilSellerHolde extends RecyclerView.ViewHolder {
        private RelativeLayout sellerPmvilRl;
        private ImageView sellerPmvilIv;
        private TextView sellerPmvilTvname;
        private TextView sellerPmvilTvmoney;
        private TextView pmlset_se;
        private TextView seller_pmvil_tv_hkrq;
        private TextView seller_pmvil_tv_lv;
        private TextView seller_pmvil_tv_kbf;

        public PmvilSellerHolde(@NonNull View itemView) {
            super(itemView);
            intePmvilSeller(itemView);
            intePmvilSeller1(itemView);
        }

        private void intePmvilSeller(@NonNull View itemView) {
            sellerPmvilRl = itemView.findViewById(R.id.seller_pmvil_item_rl);
            sellerPmvilIv = itemView.findViewById(R.id.seller_pmvil_item_iv);
            pmlset_se = itemView.findViewById(R.id.pmlset_se);
        } private void intePmvilSeller1(@NonNull View itemView) {
            sellerPmvilTvname = itemView.findViewById(R.id.seller_pmvil_item_tv_name);
            sellerPmvilTvmoney = itemView.findViewById(R.id.seller_pmvil_item_tv_money);
            seller_pmvil_tv_kbf = itemView.findViewById(R.id.seller_pmvil_tv_kbf);
            seller_pmvil_tv_lv = itemView.findViewById(R.id.seller_pmvil_tv_lv);
            seller_pmvil_tv_hkrq = itemView.findViewById(R.id.seller_pmvil_tv_hkrq);
        }
    }
}
